home *** CD-ROM | disk | FTP | other *** search
/ Aminet 20 / Aminet 20 (1997)(GTI - Schatztruhe)[!][Aug 1997].iso / Aminet / dev / misc / TdDBdevkit.lha / DataBase / Include / libraries / tddbase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-02  |  6.7 KB  |  166 lines

  1. #ifndef LIBRARIES_TDDBASE_H
  2. #define LIBRARIES_TDDBASE_H
  3.  
  4. #ifndef EXEC_TYPES_H
  5. #include <exec/types.h>
  6. #endif
  7.  
  8. #ifndef EXEC_SEMAPHORES_H
  9. #include <exec/semaphores.h>
  10. #endif
  11.  
  12. #ifndef DOS_DOS_H
  13. #include <dos/dos.h>
  14. #endif
  15.  
  16. #ifndef UTILITY_TAGITEM_H
  17. #include <utility/tagitem.h>
  18. #endif
  19.  
  20. /*
  21.  * This structure is the shared part of a database
  22.  */
  23. struct DataBase
  24. {
  25.           struct Node Node;             /* PRIVATE: Dont tuch */
  26.  
  27.           /*
  28.            * Here can you find out who and how many programms that are 
  29.      * using this database at any time.
  30.      */
  31.           UWORD UseCnt;                                                         /* Number of opened databases */
  32.           struct MinList HandleList;                        /* List with handlers */
  33.           struct SignalSemaphore HandleSem;
  34.  
  35.           ULONG DataID;                           /* Identifies the contents of DBase */
  36.           ULONG FileType;                         /* Gives fileformat */
  37.  
  38.           ULONG Flags;                            /* Reserved for future usage */
  39.  
  40.           ULONG Nodes;                            /* Number of nodes that belongs to this dbase */
  41.  
  42.           /* There exists private data below */
  43. };
  44.  
  45. #ifndef MakeID
  46. #define MakeID(a,b,c,d)       ((a<<24)|(b<<16)|(c<<8)|d)
  47. #endif
  48.  
  49. /* This is the only recognized FileType that is suported. */
  50. #define   FILID_STATIC        MakeID('D','B','1','0')
  51.  
  52. /* Use this generic DataID if you do not wish to use datarecognizion. */
  53. #define DBID_NOID             0
  54.  
  55. /* These 2 DataID values are only for testing. Other DataID values can only
  56.  * be registerd via betasoft. */
  57. #define DBID_TEST1            1
  58. #defien DBID_TEST2            2
  59.  
  60. /* This is the process-specific parts of each database. */
  61. struct DBHandle
  62. {
  63.           struct MinNode       Node;              /* Linkage in handlerlist. */
  64.           struct DataBase *DBase;                 /* Points back to database */
  65.           struct Process      *Process; /* The process this handle is on */
  66.           ULONG                          Error;             /* Last errorcode */
  67.  
  68.           /* More private data follows! */
  69. };
  70.  
  71. /* Error codes */
  72. #define Err_NoErr             0                   /* Everything went just fine */
  73. #define Err_NoNode            1                   /* You tried to access a non-existing node */
  74. #define Err_NoMem             2                   /* Ran out of memory */
  75. #define Err_DosErr            3                   /* FileIO error */
  76. #define Err_NotDBase          4                   /* Not a database-file */
  77. #define Err_NodeBusy          5                   /* Cant get acess to node */
  78.  
  79. /* This structure defines a node in memory */
  80. struct DBNode
  81. {
  82.           struct SignalSemaphore Semaphore;       /* PRIVATE: DONT TOUCH! */
  83.           UWORD Flags;                                                          /* Flags, see below for bit-defs */
  84.           ULONG NodeNr;                                                         /* This nodes number */
  85.           struct DataStorage *DataList;           /* List with all data */
  86.           struct Process *LockProc;                         /* The process that has a lock on node */
  87. };
  88.  
  89. /* NodeFlags */
  90. #define NF_Changed  (1l<<0)             /* You have changed contents of this node */
  91. #define NF_New                (1l<<1)             /* Node has just been created */
  92. #define NF_Locked   (1l<<2)             /* Node has a "soft" lock on it */
  93.  
  94. #define NB_Changed  (0)
  95. #define NB_New                (1)
  96. #define NB_Locked   (2)
  97.  
  98. /* Flags for TDDB_GetNode() */
  99. #define MODEF_READ            (1l<<0)             /* Get read acess */
  100. #define MODEF_WRITE           (1l<<1)             /* Get read/write acess to nide */
  101. #define MODEF_NOWAIT          (1l<<2)             /* Dont wait for it to become free */
  102.  
  103. /* Here comes some defines/macros to be used on field ID's */
  104.  
  105. #define DATATYPES   (0xf0000000)        /* These bits are reserved for datatype */
  106.  
  107. #define CONTROL     (0x00000000)        /* Internal controltags DONT TOUCH! */
  108. #define INT                             (0x80000000)        /* 32 bit value */
  109. #define STRING                (0x40000000)        /* NULL terminated string */
  110. #define   BINARY              (0xc0000000)        /* Binary data */
  111.  
  112. /* These macros can be used to define correct FieldID values */
  113. #define IntTag(v)   (INT + v)
  114. #define StrTag(v)   (STRING + v)
  115. #define BinTag(v)   (BINARY + v)
  116.  
  117. /* These macros can be used to check a FieldID value against a datatype */
  118. #define IsControl(v) (CONTROL==(v & DATATYPES))
  119. #define IsInt(v)    (INT==(v & DATATYPES))
  120. #define IsString(v) (STRING==(v & DATATYPES))
  121. #define IsBinary(v) (BINARY==(v & DATATYPES))
  122.  
  123. // This structure is returned by TDDB_GetDataItem()
  124. struct DataStorage
  125. {
  126.           ULONG ds_ID;                                      /* Identifies the field data belongs to. */
  127.  
  128.           union
  129.           {
  130.                     ULONG     ds_Nummer;                    /* Data for IntTag */
  131.                     STRPTR    ds_String;                    /* Pointer to StrTag string */
  132.                     APTR      ds_Binary;                    /* Pointer to BinTag databuffer. */
  133.           };
  134. };
  135.  
  136. /* This message is allocated by you and then replyed when something happens. */
  137. struct UpdateMsg
  138. {
  139.           struct Message Msg;
  140.           struct DataBase *DBase;                 /* Points to origin database */
  141.           struct Process *Proc;                   /* The process causing this message */
  142.           ULONG Type;                                                 /* What have happened? */
  143.           ULONG NodeNr;                                     /* To what node did it happen? */
  144.           ULONG MoreData;                                   /* Is there more to know? */
  145. };
  146.  
  147. /* Types of UpdateMsg know today */
  148. #define MSG_NEWNODE           0                   /* Node has been created. */
  149. #define MSG_DELNODE           1                   /* Node has been deleted. */
  150. #define MSG_NODELOCK          2                   /* Node is now to considered locked */
  151. #define MSG_NODEUNLOCK        3                   /* Node nolonger is locked */
  152. #define MSG_CHANGED           4                   /* There are new data stored in it */
  153. #define MSG_USER              5                   /* Caused by a call to TDDB_ShowUpdate() */
  154. #define MSG_ABORTED           6                   /* Message has been aborted */
  155. #define MSG_SWAP              7                   /* Nodes are swaped, MoreData is number of */
  156.                                                                                 /* the second node */
  157.  
  158. /*
  159.  * Tags for TDDB_SeekBase() and TDDB_Find#?()
  160.  */ 
  161. #define SBT_Dummy             TAG_USER
  162.  
  163. #define SBT_StartNode         (SBT_Dummy+1)       /* ti_Data is nodenr to start from */
  164.                                                                                                     /* instead of 0 */
  165.  
  166. #endif // LIBRARIES_TDDBASE_H